import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/pages/clubs/announcement/announcement_controller.dart';
import 'package:flutter_changdian_football/widget/custom_button.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:get/get.dart';

/// 发布公告
class AnnouncementPage extends StatelessWidget {
  const AnnouncementPage({super.key, this.clubId});

  final String? clubId;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xffF8FAF9),
      resizeToAvoidBottomInset: false,
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: const Color(0xffF8FAF9),
        elevation: 0,
        title: Text(
          '发布公告',
          style: TextStyle(fontSize: 16.sp, color: const Color(0xff333333)),
        ),
        iconTheme: const IconThemeData(
          color: Color(0xff333333)
        ),
      ),
      body: GetBuilder<AnnouncementController>(
        init: AnnouncementController(clubId: clubId ?? ''),
        builder: (announcementController) {
          return Column(
            children: [
              SizedBox(height: 20.w,),

              Container(
                margin: EdgeInsets.symmetric(horizontal: 17.w),
                padding: EdgeInsets.symmetric(vertical: 12.w, horizontal: 14.w),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(8.r)
                ),
                child: Column(
                  children: [
                    SizedBox(
                      child: Row(
                        children:  [
                          SizedBox(
                            child: Text('公告内容', style: TextStyle(fontSize: 15.sp, color: const Color(0xff323232), fontWeight: FontWeight.w400),),
                          ),

                          const Spacer(),

                          SizedBox(
                            child: Text('${announcementController.bulletinController.text.length}/255', style: TextStyle(fontSize: 14.sp, color: const Color(0xff999999), fontWeight: FontWeight.w400),),
                          ),

                        ],
                      ),
                    ),

                    SizedBox(height: 12.w,),

                    Container(
                      height: 100.w,
                      width: double.infinity,
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(12.r),
                      ),
                      child: Column(
                        children: [
                          Expanded(
                            child: TextField(
                              keyboardType: TextInputType.text,
                              maxLines: 12,
                              controller: announcementController.bulletinController,
                              maxLength: 255,
                              decoration: InputDecoration(
                                contentPadding: EdgeInsets.zero,
                                border: const OutlineInputBorder(
                                  borderSide: BorderSide.none,
                                ),
                                hintStyle: TextStyle(fontSize: 14.sp, color: const Color(0xff9E9E9E)),
                                hintText: '请输入您的公告，不超过255字',
                                counterText: '',
                              ),
                              style: TextStyle(fontSize: 14.sp, color: const Color(0xff333333)),
                              onChanged: (v) {
                                announcementController.update();
                              },
                            ),
                          )
                        ],
                      ),
                    ),
                  ],
                ),
              ),

              const Spacer(),

              Container(
                padding: EdgeInsets.symmetric(horizontal: 17.w, vertical: 20.w),
                child: Opacity(
                  opacity: announcementController.bulletinController.text.length <= 0 ? 0.5 : 1,
                  child: CustomButton(
                    text: '保存',
                    onTap: () {
                      announcementController.setClubBulletin(clubId);
                    },
                  ),
                ),
              )
            ],
          );
        }
      ),
    );
  }
}